package com.young.testcoroutine

import android.util.Log
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlin.coroutines.CoroutineContext

/**
 * Author：young
 * .
 * Time： 2022/9/14 23:44 周三
 * .
 * Desc：全局的异常获取（不会捕获阻止 app 闪退）
 */
class GlobalCoroutineExceptionHandler : CoroutineExceptionHandler {
    override val key: CoroutineContext.Key<*>
        get() = CoroutineExceptionHandler

    override fun handleException(context: CoroutineContext, exception: Throwable) {
        Log.e("young_test","我是全局的获取异常 $exception")
    }
}